/*
 * 修改分类信息
 * @Author: ljb
 * @Date: 2018-03-27 17:53:27
 * @Last Modified by: kanglin
 * @Last Modified time: 2018-08-07 18:01:53
 */

<template>
	<div class="v-admin-category-edit">
		<Form
			ref="formValidate"
			:model="formValidate"
			:label-width="80"
			name="edit__form">

			<Form-item
				:label="$t('category.is_show')"
				prop="is_show">
				<RadioGroup v-model="formValidate.is_show">
					<Radio
						label="0">
						<span>{{ $t('category.no') }}</span>
					</Radio>
					<Radio
						label="1">
						<span>{{ $t('category.yes') }}</span>
					</Radio>
				</RadioGroup>
			</Form-item>

			<Form-item
				:label="$t('category.priority')"
				prop="priority">
				<InputNumber
					:max="100000"
					:min="0"
					v-model="formValidate.priority"
					:placeholder="$t('category.please_enter_priority')"
					name="edit__priority"/>
			</Form-item>

			<Form-item>
				<Button
					type="primary"
					name="edit__submit"
					@click="updateCategory">
					{{ $t('common.update') }}
				</Button>
			</Form-item>

		</Form>
	</div>
</template>

<script>

export default {

	name: 'ProductCategoryEdit',

	props: {
		categoryDetail: {
			type: Object,
			default() {
				return {};
			},
		},
	},

	data() {
		return {
			formValidate: {
				priority: 0,

				is_show: '',
			}, // 更新产品分类时的表单

		};
	},

	watch: {
		categoryDetail() {
			if (this.categoryDetail) {
				this.formValidate.priority = this.categoryDetail.pivot.priority;

				this.formValidate.is_show = String(this.categoryDetail.pivot.is_show);
			}
		},
	},

	methods: {

		/**
         * 更新分类
         * @return {undefined}
         */
		updateCategory() {
			const new_object = {
				_method: 'PUT',

				priority: this.formValidate.priority,

				is_show: this.formValidate.is_show,
			};

			this.$emit('update', this.categoryDetail.pivot.id, new_object);
		},


	},
};
</script>
